package com.example.controller;


import com.example.pojo.LoginMsg;
import com.example.pojo.Result;
import com.example.service.LoginService;
import com.example.utils.PasswordSecurity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




@Slf4j
@CrossOrigin // 允许跨域访问
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;


    /**
     * 判断登录
     *
     * @param loginmsg
     * @return
     */
    //@CrossOrigin    //允许跨域访问
    @PostMapping
    public Result login(@RequestBody LoginMsg loginmsg)throws  Exception {

        log.info("登录请求参数：{}", loginmsg);
        LoginMsg loginResult = loginService.login(loginmsg);
        if (loginResult != null && PasswordSecurity.checkPassword(loginmsg.getPassword(), loginResult.getPassword())) {
            return Result.success(loginResult);
        }
        return Result.fail();
    }


}
